<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="./vue.min.js"></script>
  <script src="./axios.min.js"></script>

  <!-- 本地引入lib-master -->
  <link rel="stylesheet" type="text/css" href="lib-master/theme-chalk/index.css"/>
  <script src="lib-master/index.js" type="text/javascript" charset="utf-8"></script>
</head>

<body>
<div id="app">
<template>
  <div class="mod-config">
    <el-form :inline="true" :model="pojo" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input v-model="pojo.key" placeholder="参数名" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
        <el-button  type="primary" @click="addOrUpdateHandle()">新增</el-button>
        <el-button  type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column>
      <el-table-column
        prop="id"
        header-align="center"
        align="center"
        label="主键">
      </el-table-column>
      <el-table-column
        prop="goodsId"
        header-align="center"
        align="center"
        label="商品id">
      </el-table-column>
      <el-table-column
        prop="userId"
        header-align="center"
        align="center"
        label="用户id">
      </el-table-column>
      <el-table-column
        prop="tourDivStatus"
        header-align="center"
        align="center"
        label="拼团状态(0.开启,1关闭,2.失效,3.完成)">
      </el-table-column>
      <el-table-column
        prop="startTime"
        header-align="center"
        align="center"
        label="开始时间">
      </el-table-column>
      <el-table-column
        prop="endTime"
        header-align="center"
        align="center"
        label="结束时间">
      </el-table-column>
      <el-table-column
        prop="joinNum"
        header-align="center"
        align="center"
        label="参团人数">
      </el-table-column>
      <el-table-column
        prop="orderClusteringCount"
        header-align="center"
        align="center"
        label="成团人数">
      </el-table-column>
      <el-table-column
        prop="orderLeastClusteringCount"
        header-align="center"
        align="center"
        label="成团最少人数">
      </el-table-column>
      <el-table-column
        prop="goodsPrice"
        header-align="center"
        align="center"
        label="商品原价">
      </el-table-column>
      <el-table-column
        prop="headPrice"
        header-align="center"
        align="center"
        label="开团价格">
      </el-table-column>
      <el-table-column
        prop="payPrice"
        header-align="center"
        align="center"
        label="支付金额">
      </el-table-column>
      <el-table-column
        prop="payTime"
        header-align="center"
        align="center"
        label="支付时间">
      </el-table-column>
      <el-table-column
        prop="totalAmount"
        header-align="center"
        align="center"
        label="订单总额">
      </el-table-column>
      <el-table-column
        prop="payAmount"
        header-align="center"
        align="center"
        label="应付总额">
      </el-table-column>
      <el-table-column
        prop="payState"
        header-align="center"
        align="center"
        label="支付状态(0.支付成功,1.支付失败)">
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">修改</el-button>
          <el-button type="text" size="small" @click="deleteHandle(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[2, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>

  </div>
  <el-dialog
          :title="!dataForm.id ? '新增' : '修改'"
          :close-on-click-modal="false"
          :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
                                      <el-form-item label="商品id" prop="goodsId">
            <el-input v-model="dataForm.goodsId" placeholder="商品id"></el-input>
          </el-form-item>
                                <el-form-item label="用户id" prop="userId">
            <el-input v-model="dataForm.userId" placeholder="用户id"></el-input>
          </el-form-item>
                                <el-form-item label="拼团状态(0.开启,1关闭,2.失效,3.完成)" prop="tourDivStatus">
            <el-input v-model="dataForm.tourDivStatus" placeholder="拼团状态(0.开启,1关闭,2.失效,3.完成)"></el-input>
          </el-form-item>
                                <el-form-item label="开始时间" prop="startTime">
            <el-input v-model="dataForm.startTime" placeholder="开始时间"></el-input>
          </el-form-item>
                                <el-form-item label="结束时间" prop="endTime">
            <el-input v-model="dataForm.endTime" placeholder="结束时间"></el-input>
          </el-form-item>
                                <el-form-item label="参团人数" prop="joinNum">
            <el-input v-model="dataForm.joinNum" placeholder="参团人数"></el-input>
          </el-form-item>
                                <el-form-item label="成团人数" prop="orderClusteringCount">
            <el-input v-model="dataForm.orderClusteringCount" placeholder="成团人数"></el-input>
          </el-form-item>
                                <el-form-item label="成团最少人数" prop="orderLeastClusteringCount">
            <el-input v-model="dataForm.orderLeastClusteringCount" placeholder="成团最少人数"></el-input>
          </el-form-item>
                                <el-form-item label="商品原价" prop="goodsPrice">
            <el-input v-model="dataForm.goodsPrice" placeholder="商品原价"></el-input>
          </el-form-item>
                                <el-form-item label="开团价格" prop="headPrice">
            <el-input v-model="dataForm.headPrice" placeholder="开团价格"></el-input>
          </el-form-item>
                                <el-form-item label="支付金额" prop="payPrice">
            <el-input v-model="dataForm.payPrice" placeholder="支付金额"></el-input>
          </el-form-item>
                                <el-form-item label="支付时间" prop="payTime">
            <el-input v-model="dataForm.payTime" placeholder="支付时间"></el-input>
          </el-form-item>
                                <el-form-item label="订单总额" prop="totalAmount">
            <el-input v-model="dataForm.totalAmount" placeholder="订单总额"></el-input>
          </el-form-item>
                                <el-form-item label="应付总额" prop="payAmount">
            <el-input v-model="dataForm.payAmount" placeholder="应付总额"></el-input>
          </el-form-item>
                                <el-form-item label="支付状态(0.支付成功,1.支付失败)" prop="payState">
            <el-input v-model="dataForm.payState" placeholder="支付状态(0.支付成功,1.支付失败)"></el-input>
          </el-form-item>
                  </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>
</div>
</body>
<script>
  new Vue({
    el: "#app",
    data() {
      return {
        msg: "列表页面",
        pojo: {
          key: ''
        },
        dataList: [],
        pageIndex: 1,
        pageSize: 2,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        visible: false,
        dataForm: {
                                      id: 0,
                                                  goodsId: '',
                                                  userId: '',
                                                  tourDivStatus: '',
                                                  startTime: '',
                                                  endTime: '',
                                                  joinNum: '',
                                                  orderClusteringCount: '',
                                                  orderLeastClusteringCount: '',
                                                  goodsPrice: '',
                                                  headPrice: '',
                                                  payPrice: '',
                                                  payTime: '',
                                                  totalAmount: '',
                                                  payAmount: '',
                                                  payState: ''
                              },
        dataRule: {
                                                            goodsId: [
                { required: true, message: '商品id不能为空', trigger: 'blur' }
              ],
                                                  userId: [
                { required: true, message: '用户id不能为空', trigger: 'blur' }
              ],
                                                  tourDivStatus: [
                { required: true, message: '拼团状态(0.开启,1关闭,2.失效,3.完成)不能为空', trigger: 'blur' }
              ],
                                                  startTime: [
                { required: true, message: '开始时间不能为空', trigger: 'blur' }
              ],
                                                  endTime: [
                { required: true, message: '结束时间不能为空', trigger: 'blur' }
              ],
                                                  joinNum: [
                { required: true, message: '参团人数不能为空', trigger: 'blur' }
              ],
                                                  orderClusteringCount: [
                { required: true, message: '成团人数不能为空', trigger: 'blur' }
              ],
                                                  orderLeastClusteringCount: [
                { required: true, message: '成团最少人数不能为空', trigger: 'blur' }
              ],
                                                  goodsPrice: [
                { required: true, message: '商品原价不能为空', trigger: 'blur' }
              ],
                                                  headPrice: [
                { required: true, message: '开团价格不能为空', trigger: 'blur' }
              ],
                                                  payPrice: [
                { required: true, message: '支付金额不能为空', trigger: 'blur' }
              ],
                                                  payTime: [
                { required: true, message: '支付时间不能为空', trigger: 'blur' }
              ],
                                                  totalAmount: [
                { required: true, message: '订单总额不能为空', trigger: 'blur' }
              ],
                                                  payAmount: [
                { required: true, message: '应付总额不能为空', trigger: 'blur' }
              ],
                                                  payState: [
                { required: true, message: '支付状态(0.支付成功,1.支付失败)不能为空', trigger: 'blur' }
              ]
                              }
      }
    },
    created() {
      this.getDataList()
    },
    methods: {
      // 获取数据列表
      getDataList () {

        this.dataListLoading = true
        axios.post(`http://localhost:7000/tourdiv/tourdivorder/list?page=${this.pageIndex}&limit=${this.pageSize}`,this.pojo).then(({data}) => {
          console.log(data)
          if (data && data.code === 0) {
            this.dataList = data.page.list
            this.totalPage = data.page.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      // 新增 / 修改
      addOrUpdateHandle (id) {
        this.visible=true
        this.dataForm.id = id || 0
        this.visible = true
        if (id != null && id != 0) {
          axios.get(`http://localhost:7000/tourdiv/tourdivorder/info/${id}`).then(res => {
            console.log(res)
            this.dataForm = res.data.tourdiv
          })
        }else{
          this.dataForm = {}
        }
      },
      // 删除
      deleteHandle (id) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.id
        })
        this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          axios.post("http://localhost:7000/tourdiv/tourdivorder/delete", ids).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
                if (valid) {
          if (this.dataForm.id == null) {
            axios.post("http://localhost:7000/tourdiv/tourdivorder/save", this.dataForm).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                        message: '操作成功',
                        type: 'success',
                        duration: 1500,
                        onClose: () => {
                  this.visible = false
                  this.getDataList();
                }
              })
              } else {
                this.$message.error(data.msg)
              }
            })
          }else {
            axios.post("http://localhost:7000/tourdiv/tourdivorder/update", this.dataForm).then(
                    ({
                       data
                     }) => {
                      if (data && data.code === 0) {
                        this.$message({
                          message: '操作成功',
                          type: 'success',
                          duration: 1500,
                          onClose: () => {
                            this.visible = false
                            this.getDataList();
                          }
                        })
                      } else {
                        this.$message.error(data.msg)
                      }
                    })
          }
    }
        })
      }
    }
  })
</script>
</html>
